<%@ page contentType="text/html" %>
<%@ taglib prefix="jbfilter" uri="http://jbfilter.org/tag" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:useBean id="dao" class="org.jbfilter.test.beans.factory.DataAccessObject" scope="application"/>
<c:set var="datePattern" value="dd/MM/yyyy"/>
<c:set var="checked">checked="checked"</c:set>
<c:set var="selected">selected="selected"</c:set>

<html>
<head>
<title>StringFilterComponent</title>
</head>
<body>

<jbfilter:filter id="myFilterString" varComponents="comps" providerName="bean" clean="${param.clean}">
	<jbfilter:stringComponent
		id="fc"
		propertyPath="${param.propertyPath}"
		value="${param.value}"
		caseSensitive="${param.caseSensitive}"
		caseSensitiveCleanValue="${param.caseSensitiveCleanValue}"
		inverted="${param.inverted}"
		enabled="${!param.disabled}"
		nullTestingEnabled="${param.nullTestingEnabled}"
		valueCleanValue="${param.valueCleanValue}"
		valueForNull="${param.valueForNull}"
		regex="${param.regex}"
		regexCleanValue="${param.regexCleanValue}"
		/>
</jbfilter:filter>

<form action="">
	<table>
		<tr>
			<td>propertyPath </td>
			<td>
				<select name="propertyPath">
					<option value="firstName"<c:if test="${comps.fc.propertyPath == 'firstName'}"> ${selected}</c:if>>firstName</option>
					<option value="lastName"<c:if test="${comps.fc.propertyPath == 'lastName'}"> ${selected}</c:if>>lastName</option>
					<option value="particle"<c:if test="${comps.fc.propertyPath == 'particle'}"> ${selected}</c:if>>particle</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>value </td>
			<td><input type="text" name="value" value="<c:if test="${comps.fc.value == null}">${param.valueForNull}</c:if>${comps.fc.value}"/></td>
		</tr>
		<tr>
			<td>valueCleanValue </td>
			<td><input type="text" name="valueCleanValue" value="${comps.fc.valueCleanValue}"/></td>
		</tr>
		<tr>
			<td>valueForNull </td>
			<td><input type="text" name="valueForNull" value="${param.valueForNull}"/></td>
		</tr>
		<tr>
			<td>caseSensitive</td>
			<td><input type="checkbox" name="caseSensitive" value="true"<c:if test="${comps.fc.caseSensitive}"> ${checked}</c:if>/>case sensitive</td>
		</tr>
		<tr>
			<td>caseSensitiveCleanValue</td>
			<td>
				<input type="radio" name="caseSensitiveCleanValue" value="true"<c:if test="${comps.fc.caseSensitiveCleanValue}"> ${checked}</c:if>/>true
				<input type="radio" name="caseSensitiveCleanValue" value="false"<c:if test="${!comps.fc.caseSensitiveCleanValue}"> ${checked}</c:if>/>false
			</td>
		</tr>
		<tr>
			<td>regex</td>
			<td><input type="checkbox" name="regex" value="true"<c:if test="${comps.fc.regex}"> ${checked}</c:if>/>regex</td>
		</tr>
		<tr>
			<td>regexCleanValue</td>
			<td>
				<input type="radio" name="regexCleanValue" value="true"<c:if test="${comps.fc.regexCleanValue}"> ${checked}</c:if>/>true
				<input type="radio" name="regexCleanValue" value="false"<c:if test="${!comps.fc.regexCleanValue}"> ${checked}</c:if>/>false
			</td>
		</tr>
		<tr>
			<td>inverted</td>
			<td><input type="checkbox" name="inverted" value="true"<c:if test="${comps.fc.inverted}"> ${checked}</c:if>/>inverted</td>
		</tr>
		<tr>
			<td>disabled</td>
			<td><input type="checkbox" name="disabled" value="true"<c:if test="${!comps.fc.enabled}"> ${checked}</c:if>/>disabled</td>
		</tr>
		<tr>
			<td>nullTestingEnabled</td>
			<td><input type="checkbox" name="nullTestingEnabled" value="true"<c:if test="${comps.fc.nullTestingEnabled}"> ${checked}</c:if>/>nullTestingEnabled</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td>
				<input type="submit" value="Ok"/>
				<input type="submit" name="clean" value="Clean"/>
			</td>
		</tr>
	</table>
</form>

<jbfilter:doFilter
	filterId="myFilterString"
	items="${dao.allComposers}"
	varFilteredItems="filteredComposers"/>

<table border="1">
	<thead>
		<tr>
			<td>id</td>
			<td>Name</td>
			<td>born</td>
			<td>died</td>
			<td>country</td>
		</tr>
	</thead>
	<tbody>
		<c:forEach items="${filteredComposers}" var="composer">
			<tr>
				<td>${composer.id}</td>
				<td>${composer.name}</td>
				<td><fmt:formatDate value="${composer.born}" pattern="${datePattern}"/></td>
				<td><c:if test="${empty composer.died}">&nbsp;</c:if><fmt:formatDate value="${composer.died}" pattern="${datePattern}"/></td>
				<td>${composer.country.displayName}</td>
			</tr>
		</c:forEach>
	</tbody>
</table>
comps.fc.propertyPath : ${comps.fc.propertyPath}<br/>
comps.fc.value : ${comps.fc.value}<br/>
comps.fc.valueCleanValue : ${comps.fc.valueCleanValue}<br/>
comps.fc.caseSensitive : ${comps.fc.caseSensitive}<br/>
comps.fc.caseSensitiveCleanValue : ${comps.fc.caseSensitiveCleanValue}<br/>
comps.fc.regex : ${comps.fc.regex}<br/>
comps.fc.regexCleanValue : ${comps.fc.regexCleanValue}<br/>
comps.fc.inverted : ${comps.fc.inverted}<br/>
comps.fc.enabled : ${comps.fc.enabled}<br/>
comps.fc.nullTestingEnabled : ${comps.fc.nullTestingEnabled}<br/>
comps.fc.active : ${comps.fc.active}<br/>
comps.fc.value == null : ${comps.fc.value == null}<br/>
${comps}

</body>

</html>